//
//  WTFDWHDVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/18.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "WTFDWHDVC.h"

@interface WTFDWHDVC ()

@property (strong, nonatomic) UILabel *noDataLabel;
@property (strong, nonatomic) UIView *fgxView;
@property (copy, nonatomic) NSString *banji;
@property (copy, nonatomic) NSString *riqi;
@property (copy, nonatomic) NSString *keyStr;//搜索
@property (strong, nonatomic) SYNoLabel *noLab;

@end

@implementation WTFDWHDVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initSubView];
}
- (void)initSubView{
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.leftTableList.view];
    [_leftTableList.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(self.view.mas_centerX).offset(-50);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    
    _fgxView = [[UIView alloc]init];
    _fgxView.backgroundColor = LINCOLOR;
    [self.view addSubview:_fgxView];
    _fgxView.hidden = YES;
    [_fgxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftTableList.view.mas_right);
        make.width.equalTo(@1);
        make.top.equalTo(self.leftTableList.view.mas_top);
        make.bottom.equalTo(@0);
    }];
    
    [self.view addSubview:self.rightList.view];
    [_rightList.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.fgxView.mas_right);
        make.top.equalTo(self.leftTableList.view.mas_top);
        make.right.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    [self.view addSubview:self.noDataLabel];
    [_noDataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@44);
        make.bottom.equalTo(@0);
    }];
    [self requestDataList];
    //点击了cell或者搜索
    __weak typeof(self) weakSelf = self;
    self.leftTableList.block = ^(SYWenTiFuDaoModel * _Nonnull model, NSString * _Nonnull wordKey) {
        [weakSelf.rightList requestData:model];
    };
    self.leftTableList.wtBlock = ^(NSInteger index) {
        [weakSelf requestDataList];
    };
    
    
    self.noLab = [[SYNoLabel alloc] initWithNameStr:@"" contView:self.view];
    
//    self.noLab.backgroundColor = [UIColor redColor];
    [_noLab mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(0);
        make.left.equalTo(self.view.mas_left).offset(0);
        make.right.bottom.equalTo(self.view).offset(0);
//        make.width.mas_equalTo(320);
//        make.height.mas_equalTo(540);
    }];
//    self.leftTableList.view.hidden = NO;
//    self.rightList.view.hidden = NO;
//    self.fgxView.hidden = NO;
}

- (void)requestKeyBanJi:(NSString *)banji riqi:(NSString *)riqi keyStr:(NSString *)keyStr{
    
    
    self.keyStr = keyStr;
    _banji = banji;
    _riqi = riqi;
    [self requestDataList];
}


- (void)requestDataList {
    if (self.keyStr.length == 0) {
        self.keyStr = @"";
    }
    __weak typeof(self) weakSelf = self;
    [MBProgressHUD mj_showMessage:nil toView:self.view];
    if (_banji.length == 0) {
        _banji = @"0";
    }
    [SYRequestAPI fd_requestTutorQuestionTutorServiceIsAnswer:@"0" keyword:self.keyStr classId:_banji pageIndex:0 pageSize:1000 success:^(NSMutableArray *listArr) {
        [MBProgressHUD mj_hideHUDForView:self.view];
        [weakSelf.leftTableList chuanrushujuDataListArr:listArr];
        if (listArr.count == 0) {
            weakSelf.noLab.hidden = NO;
        } else {
            weakSelf.noLab.hidden = YES;
        }
         weakSelf.fgxView.hidden = NO;
        if (listArr.count > 0) {
            weakSelf.leftTableList.view.hidden = NO;
            weakSelf.rightList.view.hidden = NO;
            [weakSelf.rightList requestData:listArr.firstObject];
        } else {//没有数据右边
            [weakSelf.rightList requestNotData];
        }

    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self.view];
//        [MBProgressHUD zr_showError:error.domain];
//        weakSelf.noDataLabel.hidden = NO;
         weakSelf.noLab.hidden = NO;
        //没有数据进行没有数据的操作
        [weakSelf.leftTableList chuanrushujuDataListArr:[NSMutableArray array]];
        [weakSelf.rightList requestNotData];
        weakSelf.fgxView.hidden = YES;
    }];
}

- (void)getDataAgin {
    
}


- (WenTiFuDaoLeftTableTableViewController *)leftTableList{
    if (!_leftTableList) {
        WenTiFuDaoLeftTableTableViewController *view = [[WenTiFuDaoLeftTableTableViewController alloc]init];
        _leftTableList = view;
        _leftTableList.view.hidden = YES;
    }
    return _leftTableList;
}
- (WTFDRightTableView *)rightList{
    if (!_rightList) {
        WTFDRightTableView *view = [[WTFDRightTableView alloc]init];
        _rightList = view;
        _rightList.view.hidden = YES;
    }
    return _rightList;
}
- (UILabel *)noDataLabel{
    if (!_noDataLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"当前数据为空";
        label.textAlignment = 1;
        label.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(getDataAgin)];
        [label addGestureRecognizer:tap];
        _noDataLabel = label;
        _noDataLabel.hidden = YES;
    }
    return _noDataLabel;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
